home *** CD-ROM | disk | FTP | other *** search
- /*==================================================================
- File: Win32ZStringCompareTool.cpp
-
- Contains: Tool for comparing ZString information from
- a binary on Windows.
-
- Written by: Hayley Iben
-
- Copyright: 2000-2001 Connectix Corporation
-
- This source has been placed into the public domain by
- Connectix Corporation. You have the right to modify,
- distribute or use this code without any legal limitations
- or finanicial/licensing requirements. Connectix is not
- liable for any problems that result from the use of this
- code.
-
- If you have comments, feedback, questions, or would like
- to submit bug fixes or updates to this code, please email
- opensource@connectix.com.
- ==================================================================*/
-
- #include "StdAfx.h"
- #include "ZStringTool.h"
-
- #include "Win32ZString.h"
- #include "Win32ZStringTools.h"
- #include "Win32ZStringCompareTool.h"
-
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
-
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
-
- Win32ZStringCompareTool::Win32ZStringCompareTool()
- : mNewFile(INVALID_HANDLE_VALUE),
- mNewMemFile(0),
- mNewBinaryImage(0),
- mOldFile(INVALID_HANDLE_VALUE),
- mOldMemFile(0),
- mOldBinaryImage(0)
- {
- }
-
- Win32ZStringCompareTool::~Win32ZStringCompareTool()
- {
- // CleanUp.
- if (mNewFile != INVALID_HANDLE_VALUE)
- ::CloseFiles(mNewBinaryImage, mNewMemFile, mNewFile);
-
- if (mOldFile != INVALID_HANDLE_VALUE)
- ::CloseFiles(mOldBinaryImage, mOldFile, mOldFile);
- }
-
-
- /*------------------------------------------------------------------
- CompareZStrings
- ------------------------------------------------------------------*/
-
- bool
- Win32ZStringCompareTool::CompareZStrings(
- CString inSrcFile,
- CString inCmpFile,
- CString inDestFile,
- ZToolOptions inOptions)
- {
- Z_UInt32 newBinarySize;
- Z_UInt32 oldBinarySize;
-
- // Open as a memory mapped file.
- if (!::OpenMemMappedFile(inSrcFile, mNewFile, mNewMemFile,
- mNewBinaryImage, newBinarySize))
- {
- ::AfxMessageBox("Unable to open the source file.\n Comparison will not be completed.");
- return false;
- }
-
- if (!::OpenMemMappedFile(inCmpFile, mOldFile, mOldMemFile,
- mOldBinaryImage, oldBinarySize))
- {
- ::AfxMessageBox("Unable to open the comparison file.\n Comparison will not be completed.");
- return false;
- }
-
- // Open report file.
- FILE * reportFile = fopen(inDestFile, "w+");
- if (reportFile == NULL)
- {
- ::AfxMessageBox("Unable to open the destination file.\n Comparison will not be completed.");
- return false;
- }
-
- CWaitCursor cursor;
- // Process the data.
- ZStringTool stringTool;
-
- CString fileName = inSrcFile;
- fileName.MakeLower();
- inOptions.mHasOTags = (fileName.Find(".dict")!=-1); // If the file is an override file, it has <O name= tags
-
- stringTool.ProcessBinaries(mNewBinaryImage, newBinarySize, mOldBinaryImage, oldBinarySize, inOptions);
- stringTool.PrintReport(reportFile, inOptions);
-
- fclose(reportFile);
-
- if (mNewFile != INVALID_HANDLE_VALUE)
- ::CloseFiles(mNewBinaryImage, mNewMemFile, mNewFile);
- if (mOldFile != INVALID_HANDLE_VALUE)
- ::CloseFiles(mOldBinaryImage, mOldFile, mOldFile);
-
- ::AfxMessageBox("Comparison report printed successfully.");
- return true;
- }
-
-
-
-